#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: splice03_category_dml.py 
@version:
@time: 2022/02/22 
"""
from TapClientCaseData.ColumnGenerateData.dynamic.splice02_oracle.splice04_sole_dml import *

__all__ = [
    'DML_ORACLE_CHARACTER_CATEGORY_INSERT_1',
    'DML_ORACLE_CHARACTER_CATEGORY_INSERT_2',
    'DML_ORACLE_CHARACTER_CATEGORY_UPDATE',
    'DML_ORA_NUMERIC_CATEGORY_INSERT_1',
    'DML_ORA_NUMERIC_CATEGORY_INSERT_2',
    'DML_ORA_NUMERIC_CATEGORY_UPDATE',
    'DML_ORA_DATE_CATEGORY_INSERT_1',
    'DML_ORA_DATE_CATEGORY_INSERT_2',
    'DML_ORA_DATE_CATEGORY_UPDATE',
    'DML_ORA_LOB_CATEGORY_INSERT_1',
    'DML_ORA_LOB_CATEGORY_INSERT_2',
    'DML_ORA_LOB_CATEGORY_UPDATE',
    'DML_ORACLE_RAW_INSERT_1',
    'DML_ORACLE_RAW_INSERT_2',
    'DML_ORACLE_RAW_UPDATE',
    'DML_ORA_ALL_INSERT_1',
    'DML_ORA_ALL_INSERT_2',
    'DML_ORA_ALL_UPDATE'
]


# --------- CATEGORY ---------
def generate_category(args):
    tmp = []
    for i in args:
        tmp.append(str(i))
    return f"{', '.join(tmp)}"


def CATEGORY_INSERT_1(LIST):
    insert0 = ['"pk"']
    insert1 = ['1']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_1')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_INSERT_2(LIST):
    insert0 = ['"pk"']
    insert1 = ['2']
    for ONE in LIST:
        insert0.append(ONE.get('COLUMNS')[3:])
        insert1.append(ONE.get('INSERT_2')[3:])
    return [generate_category(insert0), generate_category(insert1)]


def CATEGORY_UPDATE(LIST):
    TMP = {}
    for ONE in LIST:
        TMP.update(ONE.get('UPDATE'))
    return TMP


# ---- CHARACTER ----
DML_ORACLE_CHARACTER = [
    DML_ORACLE_CHAR,
    DML_ORACLE_VARCHAR2,
    DML_ORACLE_NCHAR,
    DML_ORACLE_NVARCHAR2
]
DML_ORACLE_CHARACTER_CATEGORY_INSERT_1 = CATEGORY_INSERT_1(DML_ORACLE_CHARACTER)
DML_ORACLE_CHARACTER_CATEGORY_INSERT_2 = CATEGORY_INSERT_2(DML_ORACLE_CHARACTER)
DML_ORACLE_CHARACTER_CATEGORY_UPDATE = CATEGORY_UPDATE(DML_ORACLE_CHARACTER)
# ---- NUMERIC ----
DML_ORA_NUMERIC = [
    DML_ORACLE_NUMBER,
    DML_ORACLE_FLOAT,
    DML_ORACLE_BINARY_FLOAT,
    DML_ORACLE_BINARY_DOUBLE,
]
DML_ORA_NUMERIC_CATEGORY_INSERT_1 = CATEGORY_INSERT_1(DML_ORA_NUMERIC)
DML_ORA_NUMERIC_CATEGORY_INSERT_2 = CATEGORY_INSERT_2(DML_ORA_NUMERIC)
DML_ORA_NUMERIC_CATEGORY_UPDATE = CATEGORY_UPDATE(DML_ORA_NUMERIC)
# ---- DATE ----
DML_ORA_DATE = [
    DML_ORACLE_DATE,
    DML_ORACLE_TIMESTAMP,
    DML_ORACLE_TIMESTAMP_WITH_TIME_ZONE,
    DML_ORACLE_TIMESTAMP_WITH_LOCAL_TIME_ZONE,
]
DML_ORA_DATE_CATEGORY_INSERT_1 = CATEGORY_INSERT_1(DML_ORA_DATE)
DML_ORA_DATE_CATEGORY_INSERT_2 = CATEGORY_INSERT_2(DML_ORA_DATE)
DML_ORA_DATE_CATEGORY_UPDATE = CATEGORY_UPDATE(DML_ORA_DATE)
# ---- LOB ----
DML_ORA_LOB = [
    DML_ORACLE_BLOB,
    DML_ORACLE_CLOB,
    DML_ORACLE_NCLOB,
    DML_ORACLE_BFILE
]
DML_ORA_LOB_CATEGORY_INSERT_1 = CATEGORY_INSERT_1(DML_ORA_LOB)
DML_ORA_LOB_CATEGORY_INSERT_2 = CATEGORY_INSERT_2(DML_ORA_LOB)
DML_ORA_LOB_CATEGORY_UPDATE = CATEGORY_UPDATE(DML_ORA_LOB)
# ---- RAW ----

DML_ORA_RAW = [
    DML_ORACLE_RAW_RAW,
    DML_ORACLE_LONG_RAW
]
DML_ORA_RAW_CATEGORY_INSERT_1 = CATEGORY_INSERT_1(DML_ORA_RAW)
DML_ORA_RAW_CATEGORY_INSERT_2 = CATEGORY_INSERT_2(DML_ORA_RAW)
DML_ORA_RAW_CATEGORY_UPDATE = CATEGORY_UPDATE(DML_ORA_RAW)

DML_ORA_ALL = DML_ORACLE_CHARACTER + DML_ORA_NUMERIC + DML_ORA_DATE + DML_ORA_LOB + DML_ORA_RAW
DML_ORA_ALL_INSERT_1 = CATEGORY_INSERT_1(DML_ORA_ALL)
DML_ORA_ALL_INSERT_2 = CATEGORY_INSERT_2(DML_ORA_ALL)
DML_ORA_ALL_UPDATE = CATEGORY_UPDATE(DML_ORA_ALL)
